package com.webcamtracker.tracker.model;

import com.webcamtracker.configuration.RootPref;
import com.webcamtracker.image.Color;
import com.webcamtracker.image.color.ColorSampleFactory;
import com.webcamtracker.image.color.rgb.ColorSampler;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

public class ModelElement extends Rectangle {

    private BufferedImage image;


    public ModelElement(BufferedImage image, int x, int y, int width, int height) {
        super(x, y, width, height);
        this.image = image;

    }

    public Color getColorAt(int xpos, int ypos) {
        ColorSampler colorSampler = ColorSampleFactory.getSampler(RootPref.getColorPref().get(RootPref.KEY_COLOR_TYPE, RootPref.DEF_VALUE_COLOR_TYPE));
        return getColorAt(xpos, ypos, colorSampler);
    }

    public Color getColorAt(int xpos, int ypos, ColorSampler colorSampler) {
        return colorSampler.getColorAt(this.image, xpos, ypos);
    }

    public List<Color> getColors() {
        List<Color> result = new ArrayList<Color>();
        for (int i = this.x; i < width; i++) {
            for (int j = this.y; j < width; j++) {
                result.add(getColorAt(i, j));
            }
        }
        return result;
    }

}
